package io.netty.example.a;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author: pch
 * @description:
 * @date: 2021/5/31
 **/
public class Client {
	public static void main(String[] args) {
		new Bootstrap()
				.group(new NioEventLoopGroup())
				.channel(NioSocketChannel.class)
				.handler(new ChannelInboundHandlerAdapter(){
					@Override
					public void channelActive(ChannelHandlerContext ctx) throws Exception {
						StringBuilder sb = new StringBuilder();
						for (int i = 0; i < 10000; i++) {
							sb.append(i);
						}
						sb.append("$");
						ctx.writeAndFlush(Unpooled.buffer().writeBytes(sb.toString().getBytes()));
					}
				})
				.connect("127.0.0.1",9999);
	}
}